package com.cloudsigns.factorymanager2.engineering.customview;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;

import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import android.widget.LinearLayout;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.engineering.bean.DialogItemBean;
import com.cloudsigns.factorymanager2.engineering.bean.OrderParentBean;


/**
 * Created by tony on 2018/5/5.
 */

public class BottomDialog extends Dialog {
    private Context mContext;
    private LinearLayout dialogView;
    private OrderParentBean orderParentBean;
    private OnBottomDialogClick bottomDialogClick;

    public interface OnBottomDialogClick {
        void onDialogClick(OrderParentBean orderParentBean);
    }

    public void setBottomDialogClick(OnBottomDialogClick onBottomDialogClick) {
        bottomDialogClick = onBottomDialogClick;
    }


    public BottomDialog(Context context, OrderParentBean parentBean) {
        super(context, R.style.BottomDialog);
        this.mContext = context;
        orderParentBean = parentBean;
        init();
    }


    private void init() {

        dialogView = (LinearLayout) LayoutInflater.from(mContext)
                .inflate(R.layout.dialog_bottom, null);

        TextView tv_project_name = dialogView.findViewById(R.id.tv_project_name);
        TextView tv_engineering_name = dialogView.findViewById(R.id.tv_engineering_name);
        TextView tv_address = dialogView.findViewById(R.id.tv_address);
        TextView tv_lat = dialogView.findViewById(R.id.tv_lat);
        TextView tv_lon = dialogView.findViewById(R.id.tv_lon);

        if (null != orderParentBean) {

            tv_project_name.setText(orderParentBean.getProjectName());
            tv_engineering_name.setText(orderParentBean.getEngineeringName());
            tv_address.setText(orderParentBean.getEngineeringAddress());
            tv_lat.setText(orderParentBean.getLat() + "");
            tv_lon.setText(orderParentBean.getLon() + "");
        }

        View rl_arrow = dialogView.findViewById(R.id.rl_arrow);
        TextView btn_manage = dialogView.findViewById(R.id.btn_manage);
        rl_arrow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        btn_manage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != bottomDialogClick)
                    bottomDialogClick.onDialogClick(orderParentBean);

                dismiss();
            }
        });
        WindowManager.LayoutParams localLayoutParams = getWindow()
                .getAttributes();
        localLayoutParams.x = 0;
        localLayoutParams.y = -1000;
        localLayoutParams.gravity = Gravity.BOTTOM;
        dialogView.setMinimumWidth(10000);

        onWindowAttributesChanged(localLayoutParams);
        setCanceledOnTouchOutside(true);
        setCancelable(true);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(dialogView);
    }

}
